// 使用RAII机制对锁进行设计
#pragma once
#include <iostream>
#include <pthread.h>
using namespace std;

class MUTX
{
public:
    MUTX(pthread_mutex_t *pmtx)
        : _pmtx(pmtx)
    {
    }
    void lock()
    {
        pthread_mutex_lock(_pmtx);
    }
    void unlock()
    {
        pthread_mutex_unlock(_pmtx);
    }
    ~MUTX()
    {
    }

private:
    pthread_mutex_t *_pmtx;
};
// RAII风格的加锁方式
class LockGroud
{
public:
    LockGroud(pthread_mutex_t *pmtx) : _pmtx(pmtx)
    {
        _pmtx.lock();
    }
    ~LockGroud()
    {
        _pmtx.unlock();
    }

private:
    MUTX _pmtx;
};